package com.dream.technology.utils;

import org.springframework.util.Assert;

import java.util.UUID;

/**
 * 描述：获取随机码
 *
 * @author chen_q_i@163.com
 * 2018/12/24 : 15:04.
 * @version : 1.0
 */
public class RandomCode {


   static String getRanDomCodeUUId(){

       return UUID.randomUUID().toString().replaceAll("-","");
   }

    /**
     * 获取定长UUID 小于33位
     * @return
     */
   public static String getUUIdByLength(int length){
        Assert.isTrue(length<33,"长度必须小于33");
        String ranDomCodeUUId = getRanDomCodeUUId();
        String substring = ranDomCodeUUId.substring(0, length);
        return substring;
   }



    /**
     * 获取定长UUID 小于33位 ,指定前缀
     * @return
     */
    static String getUUIdByPrefix(int length,String prefix){
        Assert.isTrue(length<33,"长度必须小于33");
        String ranDomCodeUUId = getRanDomCodeUUId();
        String substring = ranDomCodeUUId.substring(0, length);
        return prefix+substring;
   }

  /**
   * 获取定长风控分类编码
     * @return
   */
   public static String getRiskControlClaCode(){

        //String ranDomCodeUUId = getRanDomCodeUUId();
        String substring =  getUUIdByPrefix(20, "RISK_CONTROL_CLASS_");
      return  substring;
   }

   /**
    * 获取额度中心编码
    * @return
    */
   public static String getAmountCode(){
	   return getUUIdByPrefix(20, "AMOUNT_CLASS_");
  }

    /**public static void main(String[] args) {
//        String ranDomCodeUUId = getRanDomCodeUUId();
//        System.out.println(ranDomCodeUUId);
//        String uuIdByLength = getUUIdByLength(33);
//        System.out.println(uuIdByLength.length());

//        String rc_class = getUUIdByPrefix(20, "RISK_CONTROL_CLASS_");
        String riskControlClaCode = getRiskControlClaCode();
        System.out.println(riskControlClaCode);


    }*/
}
